#include"common.hpp"
//服务端

int main()
{
    key_t key=GetKeyOrDie();
    cout<<"key:"<<ToHex(key)<<endl;
    //创建共享内存
    int shmid=CreateSharedMemory(key,defaultsize);
    cout<<"创建共享内存成功"<<endl;
    DeBug(shmid);
    char*addr=(char*)AttachSharedMemory(shmid);
    if(addr!=nullptr)
    {
        cout<<"挂接上共享内存"<<endl;
    }
    DeBug(shmid);
    cout<<"开始写入数据"<<endl;
    sleep(5);
    //开始写入数据
    for(char ch='A';ch<='Z';ch++)
    {
        addr[ch-'A']=ch;
        sleep(1);
    }
    sleep(10);
    int ret=DetachShareMemory(addr);
    if(ret==0)
    {
        cout<<"取消挂接"<<endl;
    }
    DeBug(shmid);
    //sleep(10);
    DeletingSharedMemory(shmid);
    return 0;
}